package peng.yang.express.VolleyUtils;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.util.List;

import DataBaseUtils.SQLLiteHelperPhone;
import peng.yang.express.Bean.PhoneMembers;
import peng.yang.express.Bean.SortModel;
import peng.yang.express.Util.PhoneMembersDao;

/**
 * Created by Administrator on 2016/6/29.
 */
public class ImageSave  {
    List<SortModel> phoneMember;
    Context context;

    public ImageSave(  List<SortModel> phoneMember, Context context) {
        this.phoneMember = phoneMember;
        this.context = context;
    }
    public void imageSave() {
        new Thread() {

            private SQLLiteHelperPhone helperPhone;

            public void run() {

                for (int i = 0; i < phoneMember.size(); i++) {
                    PhoneMembers member = new PhoneMembers();
                    member.setNetImageUrl(phoneMember.get(i).getImageId());
                    member.setExpName(phoneMember.get(i).getName());
                    member.setPhone(phoneMember.get(i).getNum());
                    member.setSimpleName(phoneMember.get(i).getSigleName());

                    String url = phoneMember.get(i).getImageId();
                    BitmapUtil util = new BitmapUtil(context);
                    int index = url.lastIndexOf("/");
                    String path = url.substring(index+1, url.length());
                    Log.e("ImageSave_path",path);
                    util.savePicture(phoneMember.get(i).getImageId(),path);
                    member.setFileImagePath(path);
                    PhoneMembersDao membersDao = new PhoneMembersDao(context);
                    membersDao.insert(member);
                }
            }
        }.start();
    }
}


